﻿//Copyright (C) <2013>  <jonathan cleeve norton> All Rights Reserved All Rights Reserved All Rights Reserved 
//Contact jon.norton@fin-plus.co.uk website <http://www.fin-plus.co.uk/>
using System;

namespace FinPlusAssembler
{
    public static class DateExtension
    {
        public static DateTime NextWorkDay(this DateTime value, int add)
        {
            var resDate = value;
            int found = 0;
            int step = add > 0 ? 1 : -1;
            while (Math.Abs(found) < Math.Abs(add))
            {
                resDate = resDate.AddDays(step);
                if (resDate.DayOfWeek != DayOfWeek.Sunday && resDate.DayOfWeek != DayOfWeek.Saturday)
                    found++;
            }
            return resDate;
        }

        public static string FormatDateTime(this DateTime value, string dateFormat = "dd-MMM-yyyy", string dateFomatLong = "dd-MMM-yyyy  HH:mm:ss")
        {
            if (value.TimeOfDay.TotalSeconds == 0)
                return value.ToString(dateFormat);

            return value.ToString(dateFomatLong);
        }
    }
}
